package com.ruoyi.project.digital.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.digital.domain.Phrases;
import com.ruoyi.project.digital.service.IPhrasesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户常用语（chatGPT对接数据库）Controller
 * 
 * @author ruoyi
 * @date 2023-12-03
 */
@RestController
@RequestMapping("/digital/phrases")
public class PhrasesController extends BaseController
{
    @Autowired
    private IPhrasesService phrasesService;

    /**
     * 查询用户常用语（chatGPT对接数据库）列表
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:list')")
    @GetMapping("/list")
    public TableDataInfo list(Phrases phrases)
    {
        startPage();
        List<Phrases> list = phrasesService.selectPhrasesList(phrases);
        return getDataTable(list);
    }

    /**
     * 导出用户常用语（chatGPT对接数据库）列表
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:export')")
    @Log(title = "用户常用语（chatGPT对接数据库）", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Phrases phrases)
    {
        List<Phrases> list = phrasesService.selectPhrasesList(phrases);
        ExcelUtil<Phrases> util = new ExcelUtil<Phrases>(Phrases.class);
        return util.exportExcel(list, "phrases");
    }

    /**
     * 获取用户常用语（chatGPT对接数据库）详细信息
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(phrasesService.selectPhrasesById(id));
    }

    /**
     * 新增用户常用语（chatGPT对接数据库）
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:add')")
    @Log(title = "用户常用语（chatGPT对接数据库）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Phrases phrases)
    {
        return toAjax(phrasesService.insertPhrases(phrases));
    }

    /**
     * 修改用户常用语（chatGPT对接数据库）
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:edit')")
    @Log(title = "用户常用语（chatGPT对接数据库）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Phrases phrases)
    {
        return toAjax(phrasesService.updatePhrases(phrases));
    }

    /**
     * 删除用户常用语（chatGPT对接数据库）
     */
    @PreAuthorize("@ss.hasPermi('digital:phrases:remove')")
    @Log(title = "用户常用语（chatGPT对接数据库）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(phrasesService.deletePhrasesByIds(ids));
    }
}
